package com.module.ad.tengxun;

import android.app.Activity;
import android.view.ViewGroup;

import com.module.privacy.module_ad.LogADUtils;
import com.module.privacy.module_ad.SplashAdListener;
import com.qq.e.ads.splash.SplashAD;
import com.qq.e.ads.splash.SplashADListener;
import com.qq.e.comm.util.AdError;

/**
 * @author bsnl_yanxuwen
 * @date 2021/5/8 10:14
 * Description :
 */
public class TXSplashAd {
    private static final String TAG = "腾讯广告";

    /**
     * @param activity
     */
    public static void loadAd(Activity activity, String posId, SplashAdListener listener) {
        LogADUtils.d(TAG, "启动腾讯开屏广告");
        SplashAD splashAD = new SplashAD(activity, posId, new SplashADListener() {
            /**
             * 广告关闭时调用
             */
            @Override
            public void onADDismissed() {
                if (listener != null) {
                    listener.goActivity();
                }
            }

            /**
             * 广告加载失败
             */
            @Override
            public void onNoAD(AdError adError) {
                if (listener != null) {
                    listener.goActivity();
                }
                LogADUtils.d(TAG, "腾讯开屏广告加载失败 ：" + adError.getErrorMsg());
            }

            /**
             * 	广告成功展示时调用
             */
            @Override
            public void onADPresent() {

            }

            /**
             * 	广告被点击时调用
             */
            @Override
            public void onADClicked() {

            }

            /**
             * 倒计时回调
             */
            @Override
            public void onADTick(long l) {

            }

            /**
             * 广告曝光时调用
             */
            @Override
            public void onADExposure() {

            }

            /**
             * 广告加载成功的回调
             */
            @Override
            public void onADLoaded(long l) {
                LogADUtils.d(TAG, "腾讯开屏广告加载成功");
            }
        });
        ViewGroup adContainer = null;
        if (listener != null) {
            adContainer = listener.getAdView();
        }
        splashAD.fetchAndShowIn(adContainer);
    }
}
